;====================================================================
;
; Ogre3D Wrapper for Blitz3D
;
; Example01
;
;====================================================================

Include "bo3d/bo.bb"

OgreGraphics3D(800, 600, 32, False, true)

; Parameter "directory" can be a folder or a Zip-Archive.
; Archive extensions can be: .zip, .dat or .pak
; if you need an own extension, take a look into root.bb 
; and add your extension to the SELECT ext ... CASE in 
; function "SetMediaDir()"
SetMediaDir("media.zip", True)

AmbientLight 0.0, 0.0, 0.0


; let's create a pivot for "player control"
piv = CreatePivot()


; we need a camera
cam = CreateCamera(piv)
CameraRange cam, 0.1, 5000.0

PositionEntity(piv, 0.0, 10.0, -50.0)


; let's turn the light on
light = CreateLight(LT_POINT)
PositionEntity light, -100, 100, -100
LightRange(light, 500)
LightShadowRange(light)


; load a simple mesh from media.zip
box = LoadMesh("box.mesh")
PositionEntity box, 0.0, 50.0, 0.0

; load the ground mesh
ground = LoadMesh("ground.mesh")
PositionEntity ground, 0.0, -5.0, 0.0
DynamicEntity(ground, 0.0) ; mass = 0.0 = static mesh


; we want some shadows
ShadowStyle(ST_STENCIL_MOD)
EntityShadow(box)
EntityShadow(ground, False)


; create the Skybox.
; remind that you don't load a mesh or a texture. "SkyBox" 
; is a material inside "media.zip\skybox.material". You can 
; edit *.material files with a texteditor.
SkyBox("SkyBox")


MoveMouse 400, 300

Repeat
	; Cls is not needed
	
	Local msx# = MouseXSpeed()
	Local msy# = MouseYSpeed()
	
	If KeyDown(1) Then Exit
	If KeyDown(208) Or KeyDown(31) Then MoveEntity piv, 0.0, 0.0, -0.1
	If KeyDown(200) Or KeyDown(17) Then MoveEntity piv, 0.0, 0.0, 0.1
	If KeyDown(203) Or KeyDown(30) Then MoveEntity piv, -0.1, 0.0, 0.0
	If KeyDown(205) Or KeyDown(32) Then MoveEntity piv, 0.1, 0.0, 0.0
	
	If KeyHit(57)
		Local bb = CopyEntity(box)
		PositionEntity(bb, Rnd(-10.0, 10.0), 50.0, Rnd(-10.0, 10.0))
		DynamicEntity(bb)
	EndIf
	
	TurnEntity piv, 0.0, -msx * 0.005, 0.0
	TurnEntity cam, -msy * 0.005, 0.0, 0.0
	
	MoveMouse 400, 300
	
	UpdateWorld
	RenderWorld
	
	; Flip is not needed
Forever

StopOgre3D()

End

;~IDEal Editor Parameters:
;~C#Blitz3D